﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RSM.Business
{
    public class PageLayoutManager
    {
        FileManager fileManager = null;
        public PageLayoutManager()
        {
            fileManager = new FileManager();
        }

        public void CreatePageLayout(string featureName, List<Fields> fieldNames)
        {
            StringBuilder sbPageBuilder = new StringBuilder();
            string strFileName = string.Empty;
            sbPageBuilder.Append("<%@ Page language='C#' Inherits='Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c' %><%@ Register Tagprefix='SharePointWebControls' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %> <%@ Register Tagprefix='WebPartPages' Namespace='Microsoft.SharePoint.WebPartPages' Assembly='Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %> <%@ Register Tagprefix='PublishingWebControls' Namespace='Microsoft.SharePoint.Publishing.WebControls' Assembly='Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %> <%@ Register Tagprefix='PublishingNavigation' Namespace='Microsoft.SharePoint.Publishing.Navigation' Assembly='Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %><asp:Content ContentPlaceholderID='PlaceHolderMain' runat='server'>");
            foreach (Fields fC in fieldNames)
            {

                if (fC.Type == "pageName")
                {
                    strFileName = fC.FieldName;
                }
                if (fC.Type == "contentTypeID")
                {
                    sbPageBuilder.Append("</asp:Content>");
                    fileManager.WriteFileOnDisk(featureName, fC.FieldName, strFileName, sbPageBuilder);
                    sbPageBuilder.Length = 0;
                }
                if (fC.Type == "Text")
                {
                    sbPageBuilder.Append("<SharePointWebControls:TextField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "Note")
                {
                    sbPageBuilder.Append("<SharePointWebControls:NoteField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "DateTime")
                {
                    sbPageBuilder.Append("<SharePointWebControls:DateTimeField FieldName='" + fC.FieldName + "' runat='server'/>");
                }

                if (fC.Type == "User")
                {
                    sbPageBuilder.Append("<SharePointWebControls:UserField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "URL")
                {
                    sbPageBuilder.Append("<SharePointWebControls:UrlField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "Boolean")
                {
                    sbPageBuilder.Append("<SharePointWebControls:BooleanField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "Currency")
                {
                    sbPageBuilder.Append("<SharePointWebControls:CurrencyField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "Choice")
                {
                    sbPageBuilder.Append("<SharePointWebControls:DropDownChoiceField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "Number")
                {
                    sbPageBuilder.Append("<SharePointWebControls:NumberField FieldName='" + fC.FieldName + "' runat='server'/>");
                }
                if (fC.Type == "HTML")
                {
                    sbPageBuilder.Append("<PublishingWebControls:RichHtmlField FieldName='" + fC.FieldName + "' runat='server'></PublishingWebControls:RichHtmlField>");
                }
                if (fC.Type == "Image")
                {
                    sbPageBuilder.Append("<PublishingWebControls:RichImageField  FieldName='" + fC.FieldName + "' runat='server'></PublishingWebControls:RichImageField>");

                }
                if (fC.Type == "SummaryLinks")
                {
                    sbPageBuilder.Append("<PublishingWebControls:SummaryLinkFieldControl FieldName='" + fC.FieldName + "' runat='server'></PublishingWebControls:SummaryLinkFieldControl>");

                }
                if (fC.Type == "Calculated")
                {
                    sbPageBuilder.Append("<SharePointWebControls:CalculatedField FieldName='" + fC.FieldName + "' runat='server'></SharePointWebControls:CalculatedField>");

                }
                  if (fC.Type == "File")
                {
                    sbPageBuilder.Append("<SharePointWebControls:FileField FieldName='" + fC.FieldName + "' runat='server' ></SharePointWebControls:FileField>");

                }
                  if (fC.Type == "Computed")
                  {
                      sbPageBuilder.Append("<SharePointWebControls:ComputedField FieldName='" + fC.FieldName + "' runat='server' ></SharePointWebControls:ComputedField>");

                  }
                  if (fC.Type == "PublishingScheduleStartDateFieldType")
                  {
                      sbPageBuilder.Append("<PublishingWebControls:PublishingScheduleFieldControl FieldName='" + fC.FieldName + "' runat='server'></PublishingWebControls:PublishingScheduleFieldControl>");

                  }
                  if (fC.Type == "PublishingScheduleEndDateFieldType")
                  {
                      sbPageBuilder.Append("<PublishingWebControls:PublishingScheduleFieldControl FieldName='" + fC.FieldName + "' runat='server'></PublishingWebControls:PublishingScheduleFieldControl>");

                  }
               
           
            }
        }
    }
}
